<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/4/9 0009
 * Time: 09:23
 */

namespace app\home\service;


class ReportService extends BaseService
{
//    public static $appCode;
//    public static $appKey;
//    public static $sendUrl="http://111.230.168.17/Api/index.php/";
   public function __construct()
   {
       parent::__construct();
   }

    /**
     * @param string $itemId
     * @param string $answer
     * @param string $ffrom
     * @param bool $bool   false 测试数据, true正式数据
     * @return bool
     */
    public function answer($itemId='',$answer='',$ffrom='',$type='',$bool=true,$uid=0){

        if(empty($ffrom))  $ffrom  = input("post.ffrom");
        if(empty($itemId)) $itemId = input("post.itemId");
        if(empty($answer)) $answer = input("post.answer");
        if(empty($type))   $type   = input("post.type");
        if(empty($uid))    $uid    = input("post.uid");
        $host            = self::$sendUrl."YiDian/yidee/information";
        $Curl            = new Curl($host);
        $time            = time();
        $data['appCode'] = self::$appCode;
        $data['appSign'] = md5(self::$appCode.self::$appKey.$time);
        $data['time']       = $time;
        $data['ffrom']      = $ffrom; //渠道
        $data['itemId']     = $itemId;//测试题id
        $data['answer']     = $answer;//答案
        $data['type']       = $type;//答案
        $data['uid']        = $uid;//答案
        if($bool === false){
            $data['host']     = 'false';
        }
        $result = $Curl->post($data);
        $result = json_decode($result,true);
        if(empty($result)){
            $this->message=$result["msg"];
            self::ErrorLog('answer')->textWrite(date('H:i:s').'=>'.json_encode($result,JSON_UNESCAPED_UNICODE)."\t\r");
            return false;
        }
        if(empty($result['code']) || $result['code'] != 1){
            $this->message=$result["msg"];
            self::ErrorLog('answer')->textWrite(date('H:i:s').'=>'.json_encode($result,JSON_UNESCAPED_UNICODE)."\t\r");
            return false;
        }
        return $result['data'];
    }

    /**获取到题库数据
     * @param string $itemId
     * @param bool $bool
     * @return bool
     */
    public function question($itemId='',$bool=true){
        if(empty($itemId)) $itemId = input("post.itemId");

        $host            = self::$sendUrl."YiDian/yidee/info";
        $Curl            = new Curl($host);
        $time            = time();
        $data['appCode'] = self::$appCode;
        $data['appSign'] = md5(self::$appCode.self::$appKey.$time);
        $data['time']       = $time;
        $data['itemId']     = $itemId;//测试题id
        if($bool === false){
            $data['host']     = 'false';
        }

        $result = $Curl->post($data);
        $result = json_decode($result,true);

        if(empty($result)){
            $this->message=$result["msg"];
            self::ErrorLog('question')->textWrite(date('H:i:s').'=>'.json_encode($result,JSON_UNESCAPED_UNICODE)."\t\r");
            return false;
        }
        if(empty($result['code']) || $result['code'] != 1){
            $this->message=$result["msg"];
            self::ErrorLog('question')->textWrite(date('H:i:s').'=>'.json_encode($result,JSON_UNESCAPED_UNICODE)."\t\r");
            return false;
        }
        return $result['data'];
    }

    /**
     * @param string $itemId
     * @param bool $bool
     * @return bool
     */
    public function getComment($itemId='',$bool=true){
        if(empty($itemId)) $itemId = input("post.itemId");

        $host            = self::$sendUrl."YiDian/comment/comment";
        $Curl            = new Curl($host);
        $time            = time();
        $data['appCode'] = self::$appCode;
        $data['appSign'] = md5(self::$appCode.self::$appKey.$time);
        $data['time']       = $time;
        $data['itemId']     = $itemId;//测试题id
        if($bool === false){
            $data['host']     = 'false';
        }

        $result = $Curl->post($data);
        $result = json_decode($result,true);
        if(empty($result)){
            $this->message=$result["msg"];
            self::ErrorLog('getComment')->textWrite(date('H:i:s').'=>'.json_encode($result,JSON_UNESCAPED_UNICODE)."\t\r");
            return false;
        }
        if(empty($result['code']) || $result['code'] != 1){
            $this->message=$result["msg"];
            self::ErrorLog('getComment')->textWrite(date('H:i:s').'=>'.json_encode($result,JSON_UNESCAPED_UNICODE)."\t\r");
            return false;
        }
        return $result['data'];
    }
}